package cn.tedu.drs.rider.service.impl;

import cn.tedu.drs.rider.mapper.RiderMapper;
import cn.tedu.drs.rider.pojo.dto.RiderRegParam;
import cn.tedu.drs.rider.pojo.entity.Rider;
import cn.tedu.drs.rider.service.RiderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Transactional
@Slf4j
@Service
public class RiderServiceImpl implements RiderService {
    @Autowired
    private RiderMapper riderMapper;
    @Override
    public void saveRider(RiderRegParam riderRegParam) {
        log.debug("注册骑手：{}", riderRegParam);
        Rider rider=new Rider();
        BeanUtils.copyProperties(riderRegParam,rider);
        if(rider.getId()==null){
            rider.setWorkStatus("1");
            rider.setCreateTime(new Date());
            riderMapper.insert(rider);
        }else{
            rider.setUpdateTime(new Date());
            riderMapper.update(rider);
        }
    }
}
